package com.eningqu.aipen.utils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * Package:com.eningqu.aipen.utils
 * Author:starr
 * Time:2023/9/14  10:45
 * Description:
 */
public class ActivityController {

    private static volatile ActivityController mInstance;
    private List<Activity> activities=new ArrayList<>();

    private ActivityController(){ }

    public static ActivityController getInstance(){
        if(mInstance==null){
            synchronized (ActivityController.class) {
                if (mInstance == null)
                    mInstance = new ActivityController();
            }
        }
        return mInstance;
    }

    public void addActivity(Activity activity){
        activities.add(activity);
    }

    public void removeActivity(Activity activity){
        activities.remove(activity);
    }

    public void finishAll(){
        for (Activity activity:activities){
            if(!activity.isFinishing()){
                activity.finish();
            }
        }
        activities.clear();
    }

}
